package com.ls.fw.office.poi.excel.handler;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelHandler2007 extends ExcelHandlerAdapter {

	private XSSFWorkbook wb = null;

	public ExcelHandler2007(InputStream is) {
		super(is);
	}
	public ExcelHandler2007(String path){
		 super(path);
	}
	public ExcelHandler2007(String path, boolean read)
			throws InvalidFormatException, IOException {
		super(path, read);
	}

	public ExcelHandler2007(OutputStream out){
		 super(out);
	}
	
	@Override
	public Workbook createWorkbook(){
		File file = new File(this.getPath());
		try {
			if(!file.exists()){
				file.createNewFile();
				Workbook wb = new XSSFWorkbook();
				wb.createSheet();
				return wb;   // OR XSSFWorkbook
			}
			return wb = createXSSFWorkbook(this.getPath());
		} catch (InvalidFormatException e) {
			throw new IllegalArgumentException(e.getMessage(),e);
		} catch (IOException e) {
			throw new IllegalArgumentException(e.getMessage(),e);
		}
	}

	public XSSFWorkbook setWb(XSSFWorkbook wb) {
		this.wb = wb;
		return wb;
	}

	public XSSFWorkbook getWb() {
		return wb;
	}

	public String getVersion() {
		return "2003";
	}
}
